﻿using System;
using System.Net.Sockets;
using eLoop;

namespace eNets.CBK.Sockets;

sealed class SocketArgs : SocketAsyncEventArgs, IRunnable, IDisposable
{
    public SocketArgs(ITaskScheduler scheduler, ISocketArgsCompleted complete)
#if NET5_0
            : base(unsafeSuppressExecutionContextFlow: true)
#endif
    {
        this.ioComplete = complete;
        this.scheduler = scheduler;
    }

    private ITaskScheduler scheduler;
    private ISocketArgsCompleted ioComplete;

    public byte ValueToken
    {
        get;
        set;
    }

    protected override void OnCompleted(SocketAsyncEventArgs _)
    {
        this.scheduler.Schedule(this, null);
    }

    void IRunnable.Execute(object state)
    {
        this.ioComplete.OnComplete(this);
    }

    public new void Dispose()
    {
        base.Dispose();
    }
}